﻿<%@ WebHandler Language="C#" Class="researchFile" %>

using System;
using System.Web;
using CCH.DAO;
using CCH.Entity;
using System.IO;

public class researchFile : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        int res_no = int.Parse(context.Request.QueryString["res_no"]);

        research file = new researchDAO().Get_research(res_no);

        if (File.Exists(file.file_path))
        {
            context.Response.Buffer = true;
            context.Response.Clear();
            context.Response.ContentType = "application/download";
            context.Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(file.file_name, System.Text.Encoding.UTF8) + ";");

            //輸出檔案
            context.Response.BinaryWrite(File.ReadAllBytes(file.file_path));
            context.Response.Flush();
            context.Response.End();
        }
        else
        {
            context.Response.Write("檔案不存在");
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}